﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace GieldaCSharp
{
    class WykresMACD : Wykres
    {
        protected int iOdC;
        protected int iDoC;

        public WykresMACD(List<kursV> _lista, Pen _pioro, Border _b, int _Od, int _Do, int _iOdC, int _iDoC) 
        {
            pioro = _pioro; lista = _lista;
            UstalStart(_Od, _Do);
            iOdC = _iOdC;
            iDoC = _iDoC;
            b = _b;
        }

        public override void Draw(PictureBox p, Graphics g, double maxY, double minY, int N)
        {
            bool found = false;
            Point pFrom = Point.Empty;
            Point pTo = Point.Empty;

            if (0 != lista.Count)
            {

                pFrom.X = PrzeskalujX(lista[iOd].x - iOdC, N);
                pFrom.Y = PrzeskalujY(lista[iOd].kurs, maxY, minY);

                for (int i = iOd + 1; i <= iDo; i++)
                {
                    if ((0 == Convert.ToInt16(lista[i].kurs)) && (!found))
                    {
                        g.DrawLine(new Pen(Color.FromArgb(223, 223, 223), 1), b.minXn, PrzeskalujY(lista[i].kurs - iOd, maxY, minY), b.maxXn, PrzeskalujY(lista[i].kurs - iOd, maxY, minY));
                        found = true;
                    }

                    pTo.X = PrzeskalujX(lista[i].x - iOdC, N);
                    pTo.Y = PrzeskalujY(lista[i].kurs, maxY, minY);

                    g.DrawLine(pioro, pFrom, pTo);

                    pFrom.X = PrzeskalujX(lista[i].x - iOdC, N);
                    pFrom.Y = PrzeskalujY(lista[i].kurs, maxY, minY);
                }
            }

        }

    }
}
